package com.share.collection;

import java.util.*;

public class BasicGeneric {
	public static void main(String[] args) {
		List<String> c = new ArrayList<String>();
		c.add("aaa");
		c.add("bbb");
		c.add("ccc");
		for (int i = 0; i < c.size(); i++) {
			String s = c.get(i);
			System.out.print(s + "\t");
		}
		System.out.println();
		
		Collection<String> c2 = new HashSet<String>();
		c2.add("aaa");
		c2.add("bbb");
		c2.add("ccc");
		for (Iterator<String> it = c2.iterator(); it.hasNext();) {
			String s = it.next();
			System.out.println(s);
		}
		
		//sort
		List<MyName> mArray = new ArrayList<MyName>();
		mArray.add(new MyName(10));
		mArray.add(new MyName(60));
		mArray.add(new MyName(80));
		mArray.add(new MyName(30));
		
		for (Iterator<MyName> it = mArray.iterator(); it.hasNext();) {
			System.out.print(it.next().age + "\t");	
		}
		System.out.println();
		
		Collections.sort(mArray);
		for (Iterator<MyName> it = mArray.iterator(); it.hasNext();) {
			System.out.print(it.next().age + "\t");
		}
		
	}
}

class MyName implements Comparable<MyName> {
	int age;
	MyName(int age) {
		this.age = age;
	}

	public int compareTo(MyName mn) {
		if (this.age > mn.age)
			return 1;
		else if (this.age < mn.age)
			return -1;
		else
			return 0;
	}
}
